package com.e3.basdoc.currency.server;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.currency.client.CurrencyRPCService;
import com.e3.basdoc.currency.model.CurrencyModel;
import com.e3.basdoc.currency.model.CurrencyQC;
import com.e3.core.base.ServiceException;
import com.e3.web.core.client.WebException;
import com.e3.web.core.server.GwtRPCAction;
import com.e3.web.core.server.GwtRPCExecutor;
import com.e3.web.core.server.GwtRPCVoidExecutor;

public class CurrencyRPCServiceImpl extends GwtRPCAction implements	CurrencyRPCService {
	
	
	public CurrencyModel newCurrency(final CurrencyModel model) throws WebException {
		return new GwtRPCExecutor<CurrencyModel>() {
			@Override
			public CurrencyModel execute() throws ServiceException, Exception {
				return CurrencyServiceClient.getCurrencyService().newCurrency(model);
			}
		}.doExecute();
	}

	public CurrencyModel modifyCurrency(final CurrencyModel model) throws WebException {
		return new GwtRPCExecutor<CurrencyModel>() {
			@Override
			public CurrencyModel execute() throws ServiceException, Exception {
				return CurrencyServiceClient.getCurrencyService().modifyCurrency(model);
			}
		}.doExecute();
	}

	public List<CurrencyModel> getCurrencyByCondition(final CurrencyQC currencyQC) throws WebException {
		return new GwtRPCExecutor<List<CurrencyModel>>() {
			@Override
			public List<CurrencyModel> execute() throws ServiceException, Exception {
				return CurrencyServiceClient.getCurrencyQueryService().getCurrencyByCondition(currencyQC);
			}
		}.doExecute();
	}

	public void deleteCurrencys(List<CurrencyModel> models) throws WebException {
		if(models == null||models.isEmpty()){
			return;
		}
		final List<Long> ids = new ArrayList<Long>(models.size());
		for (CurrencyModel currencyModel : models) {
//			String id = currencyModel.getId();
//			ids.add(Long.parseLong(id));
			ids.add(currencyModel.getId());
		}
		
		new GwtRPCVoidExecutor() {
			@Override
			public void execute() throws ServiceException, Exception {
				CurrencyServiceClient.getCurrencyService().deleteCurrencyByIds(ids);
			}
		}.doExecute();
	}

}
